import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: asus
 * Date: 2024-12-27
 * Time: 11:29
 */
public class MajorityElement {
    public int majorityElement(int[] nums) {
        int count = 1;
        int val = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (val != nums[i]) {
                count--;
            } else {
                count++;
            }
            if (count < 0) {
                val = nums[i];
                count = 1;
            }
        }
        return val;
    }
}
